const { judgeIfMissParam } = require('../utils/common');

// 判断是否传入 isMonth 参数
async function verifyIfHasIsMonth(ctx, next) {
  const requireArr = ['isMonth'];
  const flag = judgeIfMissParam(ctx, 'overview.controller', requireArr, ctx.query);
  if (!flag) {
    const error = new Error('1004 [overview.controller_overviewUserAdd]');
    return ctx.app.emit('error', error, ctx);
  }

  const { isMonth } = ctx.query;

  // 判断month是否为空
  if (isMonth === '') {
    const error = new Error('1007 [overview.controller_overviewFinishRate]');
    return ctx.app.emit('error', error, ctx);
  }
  await next();
}

module.exports = {
  verifyIfHasIsMonth,
}